import 'package:flutter/material.dart';
import 'package:flutter_lib/utils/DpUtils.dart';
import 'package:flutter_my_web/constants/constant_status.dart';
import 'package:flutter_my_web/pages/music/music_controller.dart';
import 'package:flutter_my_web/pages/music/music_menu_widget.dart';
import 'package:flutter_my_web/utils/Utils.dart';
import 'package:flutter_my_web/widget/ImageWidget.dart';
import 'package:flutter_my_web/widget/TextWidget.dart';
import 'package:get/get.dart';

class FloatMusicWidget extends StatefulWidget {
  const FloatMusicWidget({Key? key}) : super(key: key);

  @override
  State<FloatMusicWidget> createState() => _FloatMusicWidgetState();
}

class _FloatMusicWidgetState extends State<FloatMusicWidget> {
  var logic = Get.put(MusicController());
  var progress = 0.0.obs;

  @override
  void initState() {
    super.initState();
    // logic.audioPlugin.onDurationChanged.listen((event) {
    //   print("event.inSeconds:${event.inSeconds}");
    // });
    // logic.audioPlugin.onPositionChanged.listen((event) {
    //   print("event.onPositionChanged:${event.inSeconds}");
    // });
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MusicController>(
        init: logic,
        builder: (logic) {
          return Container(
            height: 50.0.hDp,
            width: MediaQuery
                .of(context)
                .size
                .width,
            color: Color(0xdd40404c),
            child: Material(
              color: Colors.transparent,
              child: Padding(
                padding: EdgeInsets.symmetric(
                    vertical: 5.0.hDp, horizontal: 10.0.wDp),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    SizedBox(
                        height: 25.0.wDp,
                        width: 25.0.wDp,
                        child: ImageLoadUtils(
                          url:
                          "https://s1.xmcdn.com/yx/ximalaya-web-static/last/dist/images/default-album_c73995d.jpg",
                        )),
                    SizedBox(
                      width: 10.0.wDp,
                    ),
                    IconButton(
                        padding: EdgeInsets.zero,
                        onPressed: () {
                          logic.previousMusic();
                        },
                        icon: Icon(
                          Icons.keyboard_arrow_left,
                          color: Colors.white,
                          size: 30.0.wDp,
                        )),
                    SizedBox(
                      width: 5.0.wDp,
                    ),
                    IconButton(
                        padding: EdgeInsets.zero,
                        onPressed: () {
                          logic.playCurMusic();
                        },
                        icon: Icon(
                          logic.isHavePlay() ? Icons.stop : Icons.play_circle,
                          color: Colors.white,
                          size: 30.0.wDp,
                        )),
                    SizedBox(
                      width: 5.0.wDp,
                    ),
                    IconButton(
                        padding: EdgeInsets.zero,
                        onPressed: () {
                          logic.nextMusic();
                        },
                        icon: Icon(
                          Icons.keyboard_arrow_right,
                          color: Colors.white,
                          size: 30.0.wDp,
                        )),
                    Column(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SimpleText(
                          "${logic.curPlayMusicBean == null ? "" : logic
                              .curPlayMusicBean!.name}",
                          color: Colors.white,
                          fontSize: 12.sp,
                        ),
                        SizedBox(
                            width: 200.0.wDp, child: Obx(() {
                          return LinearProgressIndicator(value:logic.curMusicProgress.value,);
                        })),
                      ],
                    ),
                    SizedBox(
                      width: 5.0.wDp,
                    ),
                    // IconButton(
                    //     padding: EdgeInsets.zero,
                    //     onPressed: () {},
                    //     icon: Icon(
                    //       Icons.save,
                    //       color: Colors.white,
                    //       size: 30.0.wDp,
                    //     )),
                    // SizedBox(
                    //   width: 5.0.wDp,
                    // ),
                    IconButton(
                        padding: EdgeInsets.zero,
                        onPressed: () {
                          logic.downCurMusic();
                        },
                        icon: Icon(
                          Icons.file_download,
                          color: Colors.white,
                          size: 30.0.wDp,
                        )),
                    SizedBox(
                      width: 5.0.wDp,
                    ),
                    // IconButton(
                    //     padding: EdgeInsets.zero,
                    //     onPressed: () {},
                    //     icon: Icon(
                    //       Icons.volume_up,
                    //       color: Colors.white,
                    //       size: 30.0.wDp,
                    //     )),
                    // SizedBox(
                    //   width: 5.0.wDp,
                    // ),
                    IconButton(
                        padding: EdgeInsets.zero,
                        onPressed: () async {
                          await logic.getMusicTag();
                          showMusicMenuDialog(context, MusicController.tags);
                        },
                        icon: Icon(
                          Icons.menu,
                          color: Colors.white,
                          size: 30.0.wDp,
                        )),
                    SizedBox(
                      width: 5.0.wDp,
                    ),
                  ],
                ),
              ),
            ),
          );
        });
  }
}
